package com.celebracion;

import com.celebracion.util.DBUtil;
import com.celebracion.util.FileUtil;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.VideoView;

public class FotoPreviewActivity extends Activity {

	String fileTemp;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_foto_preview);
		
		 
		
	   
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Bundle extra = this.getIntent().getExtras();
		fileTemp=extra.getString("foto");
		String foto="file://"+fileTemp;
		ImageView imgView= (ImageView) findViewById(R.id.imVisorFoto);
		//Drawable dr=new Drawable();
		//Uri.Builder uriB=new Uri.Builder();
		//Uri uri=uriB.encodedPath(foto).build();
		//imgView.setImageURI(uri);
		 Bitmap myBitmap = BitmapFactory.decodeFile(fileTemp);
		 imgView.setImageBitmap(myBitmap);
		 
	}

	
	public void eliminar(View view){
		AlertDialog.Builder builder = new AlertDialog.Builder(this);

		// 2. Chain together various setter methods to set the dialog characteristics
		builder.setMessage(R.string.askDeleteFoto)
		       .setTitle(R.string.askTitleDeleteFoto);
		// Add the buttons
		builder.setPositiveButton(R.string.Si, new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		        	   FileUtil.deleteTempFile(fileTemp);
		        	   Intent intent=new Intent(FotoPreviewActivity.this,NombresActivity.class);
		        	   //Vacia la pila de la tarea hasta esta 
		        	   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		       		   startActivity(intent);
		           }
		       });
		builder.setNegativeButton(R.string.No, new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		        	
		           }
		       });
		// 3. Get the AlertDialog from create()
		AlertDialog dialog = builder.create();
		dialog.show();
		
	}
	
	public void guardar(View view){
		if(DBUtil.getInstance(getBaseContext()).getEventoActivo().getId()==-1){
			Toast.makeText(this, R.string.toast_modo_pruebas, Toast.LENGTH_LONG).show();
		}else{
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
	
			// 2. Chain together various setter methods to set the dialog characteristics
			builder.setMessage(R.string.askSaveFoto)
			       .setTitle(R.string.askTitleSaveFoto);
			// Add the buttons
			builder.setPositiveButton(R.string.Si, new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			        	   FileUtil.saveTempToFile(fileTemp, DBUtil.getInstance(FotoPreviewActivity.this.getBaseContext()).getEventoActivo().getId(),FotoPreviewActivity.this.getBaseContext());
			        	   Intent intent=new Intent(FotoPreviewActivity.this,NombresActivity.class);
			        	   //Vacia la pila de la tarea hasta esta 
			        	   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			       		   startActivity(intent);
			           }
			       });
			builder.setNegativeButton(R.string.No, new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			        	  
			           }
			       });
			// 3. Get the AlertDialog from create()
			AlertDialog dialog = builder.create();
			dialog.show();
		}

	}

}
